package www.yingdi365.com.viewholder;

import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import jp.wasabeef.glide.transformations.CropCircleTransformation;
import www.yingdi365.com.R;
import www.yingdi365.com.activity.ChaKanZFActivity;
import www.yingdi365.com.activity.SheZhiActivity;
import www.yingdi365.com.model.AppUser;

/**
 * Created by Administrator on 2017/3/28 0028.
 */
public class WoViewHolder extends BaseViewHolder<AppUser> {

    private final ImageView imagePhoto;
    private final TextView textName;
    private final TextView textSexAge;
    private AppUser data;

    public WoViewHolder(ViewGroup parent, @LayoutRes int res) {
        super(parent, res);
        imagePhoto = $(R.id.imagePhoto);
        textName = $(R.id.textName);
        textSexAge = $(R.id.textSexAge);
        $(R.id.viewChaKanZF).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getContext(), ChaKanZFActivity.class);
                getContext().startActivity(intent);
            }
        });
        $(R.id.viewSheZhi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getContext(), SheZhiActivity.class);
                getContext().startActivity(intent);
            }
        });
    }

    @Override
    public void setData(AppUser data) {
        super.setData(data);
        this.data = data;
        Glide.with(getContext())
                .load(data.getPhoto())
                .bitmapTransform(new CropCircleTransformation(getContext()))
                .placeholder(R.mipmap.ic_empty)
                .into(imagePhoto);
        String name = data.getName();
        if (TextUtils.isEmpty(name)) {
            name = "暂无昵称";
        }
        String sex = data.getSex();
        if (TextUtils.isEmpty(sex)) {
            sex = "";
        }
        String age = data.getAge();
        if (TextUtils.isEmpty(age)) {
            age = "0";
        }
        textName.setText(name);
        textSexAge.setText(sex + "  " + age + "岁");
    }

}
